package com.seventh.parkingrent.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.seventh.parkingrent.controller.form.ParkingSpaceFormForFront;
import com.seventh.parkingrent.domain.ParkingSpace;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 车位信息表 Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
public interface ParkingSpaceMapper extends BaseMapper<ParkingSpace> {

    @Select("select * from pr_parking_space where state = 0")
    IPage<ParkingSpaceFormForFront> selectForForm(IPage<ParkingSpaceFormForFront> page);

    @Select("select distinct parking_space_addr from pr_parking_space")
    List<String> selectParkingSpaceAddr();

    @Select(
            "<script>" +
            "select * from pr_parking_space p,pr_user u,pr_property_manager m " +
            "where p.user_id = u.user_id " +
            "and p.property_manager_id = m.property_manager_id" +
            "<if test='username!=null'>" +
            "and u.username like concat('%',#{username},'%')"+
            "</if>"+
            "<if test='propertyName!=null'>" +
            "and m.property_name like concat('%',#{propertyName},'%')"+
            "</if>"+
            "<if test='parkingSpaceAddr!=null'>" +
            "and p.parking_space_addr like concat('%',#{parkingSpaceAddr},'%')"+
            "</if>"+
            "</script>"
    )
    IPage<ParkingSpaceFormForFront> selectParkingSpaceByUsernameLike(IPage<ParkingSpaceFormForFront> page,
                                                                     @Param("username") String username,
                                                                     @Param("propertyName") String propertyName,
                                                                     @Param("parkingSpaceAddr") String parkingSpaceAddr);


}
